<?php

namespace App\Http\Controllers\ServerApi;

use App\Http\Controllers\Controller;
use App\Services\ChatRoomService\ChatService;
use App\Services\UtilManage\ResponseService;
use Illuminate\Http\Request;

class ChatController extends Controller{

    function __construct(){
        $this->chatService = new ChatService();
        $this->_r = new ResponseService();
    }
    //添加房间
    public function createRoom(Request $request ){

        $inputData = $request->exchange;

        $room_keyname = $inputData['room_keyname'];
        $room_keycheck = $inputData['room_keycheck'];
        $banker_id = $inputData['banker_id'];
        $room_max_num = $inputData['room_max'];
        $room_name = $inputData['room_name'];
        $remote_ip =  $inputData['remote_ip'];

        $result = $this->chatService->createRoom($room_keyname,$room_keycheck,$banker_id,$remote_ip,$room_name,$room_max_num);
        return $result;
    }
    //用户加入房间
    public function userjoin(Request $request) {
        $inputData = $request->exchange;

        $room_keyname = $inputData['room_keyname'];
        $user_id = $inputData['user_id'];
        $user_info = $inputData['user_info'];
        $type = $inputData['type'];
        $result = $this->chatService->userjoin($room_keyname,$user_id,$user_info,$type);
        return $result;
    }

    function keyroomOrder(Request $request){
        $inputData = $request->exchange;
        $orderDetail = $inputData['order_detail'];
        $room_id =  $inputData['room_id'];
        $uid = $inputData['uid'];
        $result = $this->chatService->addOrder($orderDetail, $room_id, $uid);
        return $result;
    }

    public function delRoom(Request $request) {
        $inputData = $request->exchange;
        $room_keyname = $inputData['room_keyname'];
        $room_keycheck = $inputData['room_keycheck'];
        $remote_ip = $inputData['remote_ip'];
        $result = $this->chatService->delRoom($room_keyname, $room_keycheck,$remote_ip);
        return $result;
    }

    public function roomDetail(Request $request) {

        $inputData = $request->exchange;
        $lottery_id = $inputData['lottery_id'];
        $room_type = $inputData['room_type'];
        $result = $this->chatService->roomDetail($lottery_id, $room_type);
        return $result;
    }

    public function websocketinit(Request $request) {

        $result = $this->chatService->websocketinit();
        return $result;
    }

    public function roomOrder(Request $request) {
        $inputData = $request->exchange;
        $user_id = $inputData['user_id'];
        $room_id = $inputData['room_id'];
        $order_detail = $inputData['order_detail'];
        $remote_ip = $inputData['remote_ip'];
        $result = $this->chatService->roomOrder($user_id,$room_id ,$order_detail, $remote_ip);
        return $result;
    }

}
